package controller;

import model.IndividualDAO;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import util.Tools;

import java.util.Calendar;
import java.util.Date;

@Controller
@RequestMapping("/shipping/peopleSumInfo")
public class IndividualAnalysis {
    @Autowired
    IndividualDAO individualDAO;

    @Autowired
    Tools tools;

    //获取员工名
    @ResponseBody
    @RequestMapping(value = "/getStaff", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
    public String staffName(@RequestParam(value = "location", required = true) String site) {
        Date end = tools.getCurrentTime(Calendar.DAY_OF_YEAR);
        if (end == null) {
            return new JSONArray().toString();
        }

        return individualDAO.getStaff(end, Calendar.DAY_OF_YEAR, site);
    }

    //工作量分析
    @ResponseBody
    @RequestMapping(value = "/getChart12", method = RequestMethod.POST, produces = "text/html;charset=utf-8")
    public String workloadHour(@RequestParam(value = "location", required = true) String site,
                               @RequestParam(value = "name", required = true) String staffId) {
        Date end = tools.getCurrentTime(Calendar.DAY_OF_YEAR);
        if (end == null) {
            return new JSONArray().toString();
        }
        return individualDAO.count(end, Calendar.DAY_OF_YEAR, site, staffId);
    }

    //工作量 按件 天
    @ResponseBody
    @RequestMapping(value = "/getChart34", produces = "text/html;charset=utf-8")
    public String piecesDay(@RequestParam(value = "location", required = true) String site,
                            @RequestParam(value = "name", required = true) String staffId) {
        Date end = tools.getCurrentTime(Calendar.HOUR_OF_DAY);
        if (end == null) {
            return new JSONArray().toString();
        }
        return individualDAO.count(end, Calendar.HOUR_OF_DAY, site, staffId);
    }

}
